package com.yh.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;




import com.yh.bean.Log;
import com.yh.service.LogService;

@RequestMapping("/log")
@Controller
public class LogController {
	

	@Resource
	private LogService logService;
	
	//1.定义一个controller 用来查找所有的日志信息
	@RequestMapping("/queryLogInfo")
	@ResponseBody
	public Map<String, Object> queryLogInfo(int page,int limit,String user_name,String startDate,String endDate){
		System.out.println("用户输入的名称"+user_name);
		System.out.println("用户输入的开始时间"+startDate);
		System.out.println("用户输入的结束时间"+endDate);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("currentPage", page);
		map.put("pageNum", limit);
		map.put("user_name", user_name);
		map.put("startDate", startDate);
		map.put("endDate", endDate);
		//1.调用业务层方法进行查询
		Map<String, Object> newMap = logService.getLogLists(map);
		//这两个是使用laytable 时需要传入的参数信息，另外还有两个在实现层已经添加过了
		newMap.put("code", 0);
		newMap.put("msg", "");
		
		return newMap;
	}
	
	@RequestMapping("/deleteLogInfo")
	@ResponseBody
	private int deleteLogInfo(@RequestBody List<Log> logs) {
		
		//1.调用业务层方法用来批量删除日志记录
		int result = logService.batchDeleteLogs(logs);
		
		
		return result;

	}
	
	@RequestMapping("/deleteLogInfoById")
	@ResponseBody
	private int deleteLogInfoById(int logId){
		//1.调用业务层方法删除，和批量删除共用一个方法
		Log log = new Log();
		log.setLogId(logId);
		List<Log> logs = new ArrayList<Log>();
		logs.add(log);
		
		int result = logService.batchDeleteLogs(logs);
		return  result;
	}
	
}
